package com.sui.bigdata.sml.web.repository.mapper;

import com.sui.bigdata.sml.web.repository.model.AzFlow;
import com.sui.bigdata.sml.web.repository.model.AzJob;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

/**
 * @author songhaicheng
 * @date 2020/1/9 11:21
 * @description
 * @reviewer
 */
@Repository
public interface AzkabanMapper {

    @Insert("insert into sml_flows(project_id,project_name,description,username,emails,failure_action,cron,deleted)" +
            " values(#{projectId},#{projectName},#{description},#{username},#{emails},#{failureAction},#{cron},#{deleted})")
    @Options(useGeneratedKeys = true)
    int insertFlow(AzFlow flow);

    @Insert("insert into sml_jobs(flow_id,job_id,param,create_time,update_time)" +
            " values(#{flowId},#{jobId},#{param},#{createTime},#{updateTime,})")
    @Options(useGeneratedKeys = true)
    int insertJob(AzJob job);

    @Update("<script>" +
            "update sml_flows" +
            "<set>" +
            "<if test='deleted!=null'> deleted=#{deleted}</if>" +
            "</set>" +
            " where deleted = '00' and" +
            "<choose>" +
            "<when test='projectName!=null'> project_name=#{projectName}</when>" +
            "<otherwise> 1!=1</otherwise>" +
            "</choose>" +
            "</script>")
    int updateFlow(AzFlow flow);
}
